{"cells":[{"cell_type":"code","execution_count":1,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"37D2EF004BD1442C89B43F3558DD4F4A","trusted":true,"collapsed":false,"scrolled":false},"outputs":[],"source":"import pandas as pd \nimport numpy as np \nimport jieba \nimport time \n\nfrom pyecharts.charts import Bar,Line,Map,Page,Pie  \nfrom pyecharts import options as opts \nfrom pyecharts.globals import SymbolType  "},{"cell_type":"code","execution_count":3,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"C72D92F3F985447283B9975C8AAB927F","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"                          goods_name shop_name   price purchase_num location\n0               乐高旗舰店官网悟空小侠系列80012孙悟   乐高官方旗舰店  1299.0   ['867人付款']    浙江 嘉兴\n1      LEGO乐高 71043收藏版哈利波特霍格沃兹城堡玩具礼物  天猫国际进口超市  3299.0   ['259人付款']    浙江 杭州\n2     LEGO乐高机械组布加迪42083粉丝收藏旗舰款玩具模型礼物  天猫国际进口超市  2799.0   ['441人付款']    浙江 杭州\n3  乐高旗舰店官网3月新品76895超级赛车系列法拉利赛车积木玩具男孩   乐高官方旗舰店   199.0   ['358人付款']    浙江 嘉兴\n4   乐高旗舰店官网3月新品得宝系列10921超级英雄实验室大颗粒益智   乐高官方旗舰店   299.0   ['126人付款']    浙江 嘉兴","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>goods_name</th>\n      <th>shop_name</th>\n      <th>price</th>\n      <th>purchase_num</th>\n      <th>location</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>乐高旗舰店官网悟空小侠系列80012孙悟</td>\n      <td>乐高官方旗舰店</td>\n      <td>1299.0</td>\n      <td>['867人付款']</td>\n      <td>浙江 嘉兴</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>LEGO乐高 71043收藏版哈利波特霍格沃兹城堡玩具礼物</td>\n      <td>天猫国际进口超市</td>\n      <td>3299.0</td>\n      <td>['259人付款']</td>\n      <td>浙江 杭州</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>LEGO乐高机械组布加迪42083粉丝收藏旗舰款玩具模型礼物</td>\n      <td>天猫国际进口超市</td>\n      <td>2799.0</td>\n      <td>['441人付款']</td>\n      <td>浙江 杭州</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>乐高旗舰店官网3月新品76895超级赛车系列法拉利赛车积木玩具男孩</td>\n      <td>乐高官方旗舰店</td>\n      <td>199.0</td>\n      <td>['358人付款']</td>\n      <td>浙江 嘉兴</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>乐高旗舰店官网3月新品得宝系列10921超级英雄实验室大颗粒益智</td>\n      <td>乐高官方旗舰店</td>\n      <td>299.0</td>\n      <td>['126人付款']</td>\n      <td>浙江 嘉兴</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"transient":{}}],"source":"df_tb = pd.read_csv(r'/home/kesci/input/legao3225/乐高淘宝数据.csv')\ndf_tb.head()"},{"cell_type":"code","execution_count":4,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"2C71158FF7ED4F7D85ACC49C5EF58466","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"stream","text":"<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 4404 entries, 0 to 4403\nData columns (total 5 columns):\ngoods_name      4404 non-null object\nshop_name       4404 non-null object\nprice           4404 non-null float64\npurchase_num    4404 non-null object\nlocation        4404 non-null object\ndtypes: float64(1), object(4)\nmemory usage: 172.1+ KB\n","name":"stdout"}],"source":"df_tb.info()"},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"42CB7267A1EF4A2587ECA0595389D4FC","trusted":true,"mdEditEnable":false},"source":"## 数据处理\n\n1. 去除重复值\n2. goods_name：暂不处理\n3. shop_name：暂不处理\n4. price：暂不处理\n5. purchase_num：提取人数\n6. 计算销售额 = price * purchase_num\n6. location：提取省份"},{"cell_type":"code","execution_count":5,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"3E636842E05D4A4C9F13502CB8029202","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"stream","text":"<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 3411 entries, 0 to 3410\nData columns (total 5 columns):\ngoods_name      3411 non-null object\nshop_name       3411 non-null object\nprice           3411 non-null float64\npurchase_num    3411 non-null object\nlocation        3411 non-null object\ndtypes: float64(1), object(4)\nmemory usage: 133.3+ KB\n","name":"stdout"}],"source":"# 去除重复值\ndf_tb.drop_duplicates(inplace=True) \n# 删除购买人数为空的记录 \ndf_tb = df_tb[df_tb['purchase_num'].str.contains('人付款')] \n\n# 重置索引 \ndf_tb = df_tb.reset_index(drop=True)\ndf_tb.info()"},{"cell_type":"code","execution_count":6,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"A73A4477607D445AA0DD469962BE5262","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"                          goods_name shop_name   price  purchase_num location  \\\n0               乐高旗舰店官网悟空小侠系列80012孙悟   乐高官方旗舰店  1299.0           867    浙江 嘉兴   \n1      LEGO乐高 71043收藏版哈利波特霍格沃兹城堡玩具礼物  天猫国际进口超市  3299.0           259    浙江 杭州   \n2     LEGO乐高机械组布加迪42083粉丝收藏旗舰款玩具模型礼物  天猫国际进口超市  2799.0           441    浙江 杭州   \n3  乐高旗舰店官网3月新品76895超级赛车系列法拉利赛车积木玩具男孩   乐高官方旗舰店   199.0           358    浙江 嘉兴   \n4   乐高旗舰店官网3月新品得宝系列10921超级英雄实验室大颗粒益智   乐高官方旗舰店   299.0           126    浙江 嘉兴   \n\n   sales_volume province  \n0     1126233.0       浙江  \n1      854441.0       浙江  \n2     1234359.0       浙江  \n3       71242.0       浙江  \n4       37674.0       浙江  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>goods_name</th>\n      <th>shop_name</th>\n      <th>price</th>\n      <th>purchase_num</th>\n      <th>location</th>\n      <th>sales_volume</th>\n      <th>province</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>乐高旗舰店官网悟空小侠系列80012孙悟</td>\n      <td>乐高官方旗舰店</td>\n      <td>1299.0</td>\n      <td>867</td>\n      <td>浙江 嘉兴</td>\n      <td>1126233.0</td>\n      <td>浙江</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>LEGO乐高 71043收藏版哈利波特霍格沃兹城堡玩具礼物</td>\n      <td>天猫国际进口超市</td>\n      <td>3299.0</td>\n      <td>259</td>\n      <td>浙江 杭州</td>\n      <td>854441.0</td>\n      <td>浙江</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>LEGO乐高机械组布加迪42083粉丝收藏旗舰款玩具模型礼物</td>\n      <td>天猫国际进口超市</td>\n      <td>2799.0</td>\n      <td>441</td>\n      <td>浙江 杭州</td>\n      <td>1234359.0</td>\n      <td>浙江</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>乐高旗舰店官网3月新品76895超级赛车系列法拉利赛车积木玩具男孩</td>\n      <td>乐高官方旗舰店</td>\n      <td>199.0</td>\n      <td>358</td>\n      <td>浙江 嘉兴</td>\n      <td>71242.0</td>\n      <td>浙江</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>乐高旗舰店官网3月新品得宝系列10921超级英雄实验室大颗粒益智</td>\n      <td>乐高官方旗舰店</td>\n      <td>299.0</td>\n      <td>126</td>\n      <td>浙江 嘉兴</td>\n      <td>37674.0</td>\n      <td>浙江</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"transient":{}}],"source":"# purchase_num处理 \ndf_tb['purchase_num'] = df_tb['purchase_num'].str.extract('(\\d+)').astype('int')\n\n# 计算销售额 \ndf_tb['sales_volume'] = df_tb['price'] * df_tb['purchase_num']\n\n#location\ndf_tb['province'] = df_tb['location'].str.split(' ').str[0]\ndf_tb.head() "},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"B1AE9E9B8DAC468C8ED5AA1C5E41E0FC","trusted":true,"mdEditEnable":false},"source":"## 数据可视化\n\n1. 乐高销量排名top10店铺 - 条形图\n2. 乐高产地数量排名top10 - 条形图\n3. 乐高产地国内销量分布 - 地图\n4. 价格分布 - 饼图\n5. 不同价格区间的销量表现 - 饼图\n6. 商品标题词云图 - 词云图"},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"8D9BB69AB4A0426598C19256C577C87E","trusted":true,"mdEditEnable":false},"source":"### 乐高销量排名Top10淘宝店铺 - 条形图"},{"cell_type":"code","execution_count":7,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"EFC3FD04BEC74E548C3C357B5D2DEC5F","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"shop_name\n乐高官方旗舰店                28669\n天猫超市                    7122\nt_1480604179663zhou     7076\nthemusicman             7000\n童趣互娱                    6722\n草莓牛奶加冰                  6500\nh543515750              5915\nliji0904                4919\n贝妮欧                     4175\nkonglone                3831\nName: purchase_num, dtype: int64"},"transient":{}}],"source":"shop_top10 = df_tb.groupby('shop_name')['purchase_num'].sum().sort_values(ascending=False).head(10)\nshop_top10"},{"cell_type":"code","execution_count":8,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"CD24888B581240D38081868639F12691","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"<pyecharts.render.display.HTML at 0x7f71ef43fa90>","text/html":"<script>\n    require.config({\n        paths: {\n            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n        }\n    });\n</script>\n\n    <div id=\"16b3a563d13d4d98ad75a67e550a771d\" style=\"width:900px; height:500px;\"></div>\n\n\n<script>\n    require(['echarts'], function(echarts) {\n        var chart_16b3a563d13d4d98ad75a67e550a771d = echarts.init(\n            document.getElementById('16b3a563d13d4d98ad75a67e550a771d'), 'white', {renderer: 'canvas'});\n        var option_16b3a563d13d4d98ad75a67e550a771d = {\n    \"color\": [\n        \"#c23531\",\n        \"#2f4554\",\n        \"#61a0a8\",\n        \"#d48265\",\n        \"#749f83\",\n        \"#ca8622\",\n        \"#bda29a\",\n        \"#6e7074\",\n        \"#546570\",\n        \"#c4ccd3\",\n        \"#f05b72\",\n        \"#ef5b9c\",\n        \"#f47920\",\n        \"#905a3d\",\n        \"#fab27b\",\n        \"#2a5caa\",\n        \"#444693\",\n        \"#726930\",\n        \"#b2d235\",\n        \"#6d8346\",\n        \"#ac6767\",\n        \"#1d953f\",\n        \"#6950a1\",\n        \"#918597\"\n    ],\n    \"series\": [\n        {\n            \"type\": \"bar\",\n            \"data\": [\n                28669,\n                7122,\n                7076,\n                7000,\n                6722,\n                6500,\n                5915,\n                4919,\n                4175,\n                3831\n            ],\n            \"barCategoryGap\": \"20%\",\n            \"label\": {\n                \"show\": true,\n                \"position\": \"top\",\n                \"margin\": 8,\n                \"fontSize\": 12\n            }\n        }\n    ],\n    \"legend\": [\n        {\n            \"data\": [\n                \"\"\n            ],\n            \"selected\": {\n                \"\": true\n            },\n            \"show\": true\n        }\n    ],\n    \"tooltip\": {\n        \"show\": true,\n        \"trigger\": \"item\",\n        \"triggerOn\": \"mousemove|click\",\n        \"axisPointer\": {\n            \"type\": \"line\"\n        },\n        \"textStyle\": {\n            \"fontSize\": 14\n        },\n        \"borderWidth\": 0\n    },\n    \"yAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            }\n        }\n    ],\n    \"xAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"axisLabel\": {\n                \"show\": true,\n                \"position\": \"top\",\n                \"rotate\": -15,\n                \"margin\": 8,\n                \"fontSize\": 12\n            },\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            },\n            \"data\": [\n                \"\\u4e50\\u9ad8\\u5b98\\u65b9\\u65d7\\u8230\\u5e97\",\n                \"\\u5929\\u732b\\u8d85\\u5e02\",\n                \"t_1480604179663zhou\",\n                \"themusicman\",\n                \"\\u7ae5\\u8da3\\u4e92\\u5a31\",\n                \"\\u8349\\u8393\\u725b\\u5976\\u52a0\\u51b0\",\n                \"h543515750\",\n                \"liji0904\",\n                \"\\u8d1d\\u59ae\\u6b27\",\n                \"konglone\"\n            ]\n        }\n    ],\n    \"title\": [\n        {\n            \"text\": \"\\u4e50\\u9ad8\\u9500\\u91cf\\u6392\\u540dTop10\\u6dd8\\u5b9d\\u5e97\\u94fa\"\n        }\n    ],\n    \"visualMap\": {\n        \"type\": \"continuous\",\n        \"min\": 0,\n        \"max\": 28669,\n        \"inRange\": {\n            \"color\": [\n                \"#50a3ba\",\n                \"#eac763\",\n                \"#d94e5d\"\n            ]\n        },\n        \"calculable\": true,\n        \"splitNumber\": 5,\n        \"orient\": \"vertical\",\n        \"showLabel\": true\n    }\n};\n        chart_16b3a563d13d4d98ad75a67e550a771d.setOption(option_16b3a563d13d4d98ad75a67e550a771d);\n    });\n</script>\n"},"transient":{}}],"source":"#条形图  \n#bar1 = Bar(init_opts=opts.InitOpts(width='1350px', height='750px')) \nbar1 = Bar() \nbar1.add_xaxis(shop_top10.index.tolist())\nbar1.add_yaxis('', shop_top10.values.tolist()) \nbar1.set_global_opts(title_opts=opts.TitleOpts(title='乐高销量排名Top10淘宝店铺'),\n                     xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),\n                     visualmap_opts=opts.VisualMapOpts(max_=28669)\n                    ) \n\nbar1.render_notebook()"},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"C5C1B14D9E3F46458ECA2A98BF1B33E9","trusted":true,"mdEditEnable":false},"source":"### 乐高产地数量排名top10"},{"cell_type":"code","execution_count":9,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"B26F501779D54C44B6EE5EDD96D27B8C","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"广东    1000\n上海     960\n北京     662\n浙江     249\n江苏     144\n辽宁     116\n天津     113\n湖北      63\n山东      33\n美国      29\nName: province, dtype: int64"},"transient":{}}],"source":"province_top10 = df_tb.province.value_counts()[:10]\nprovince_top10"},{"cell_type":"code","execution_count":10,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"68527041498940AA8037CE4B463B8BCA","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"<pyecharts.render.display.HTML at 0x7f71ed0b6668>","text/html":"<script>\n    require.config({\n        paths: {\n            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n        }\n    });\n</script>\n\n    <div id=\"9ab8f29d09654d3a9b88385195ff6ff5\" style=\"width:900px; height:500px;\"></div>\n\n\n<script>\n    require(['echarts'], function(echarts) {\n        var chart_9ab8f29d09654d3a9b88385195ff6ff5 = echarts.init(\n            document.getElementById('9ab8f29d09654d3a9b88385195ff6ff5'), 'white', {renderer: 'canvas'});\n        var option_9ab8f29d09654d3a9b88385195ff6ff5 = {\n    \"color\": [\n        \"#c23531\",\n        \"#2f4554\",\n        \"#61a0a8\",\n        \"#d48265\",\n        \"#749f83\",\n        \"#ca8622\",\n        \"#bda29a\",\n        \"#6e7074\",\n        \"#546570\",\n        \"#c4ccd3\",\n        \"#f05b72\",\n        \"#ef5b9c\",\n        \"#f47920\",\n        \"#905a3d\",\n        \"#fab27b\",\n        \"#2a5caa\",\n        \"#444693\",\n        \"#726930\",\n        \"#b2d235\",\n        \"#6d8346\",\n        \"#ac6767\",\n        \"#1d953f\",\n        \"#6950a1\",\n        \"#918597\"\n    ],\n    \"series\": [\n        {\n            \"type\": \"bar\",\n            \"data\": [\n                1000,\n                960,\n                662,\n                249,\n                144,\n                116,\n                113,\n                63,\n                33,\n                29\n            ],\n            \"barCategoryGap\": \"20%\",\n            \"label\": {\n                \"show\": true,\n                \"position\": \"top\",\n                \"margin\": 8,\n                \"fontSize\": 12\n            }\n        }\n    ],\n    \"legend\": [\n        {\n            \"data\": [\n                \"\"\n            ],\n            \"selected\": {\n                \"\": true\n            },\n            \"show\": true\n        }\n    ],\n    \"tooltip\": {\n        \"show\": true,\n        \"trigger\": \"item\",\n        \"triggerOn\": \"mousemove|click\",\n        \"axisPointer\": {\n            \"type\": \"line\"\n        },\n        \"textStyle\": {\n            \"fontSize\": 14\n        },\n        \"borderWidth\": 0\n    },\n    \"yAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            }\n        }\n    ],\n    \"xAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            },\n            \"data\": [\n                \"\\u5e7f\\u4e1c\",\n                \"\\u4e0a\\u6d77\",\n                \"\\u5317\\u4eac\",\n                \"\\u6d59\\u6c5f\",\n                \"\\u6c5f\\u82cf\",\n                \"\\u8fbd\\u5b81\",\n                \"\\u5929\\u6d25\",\n                \"\\u6e56\\u5317\",\n                \"\\u5c71\\u4e1c\",\n                \"\\u7f8e\\u56fd\"\n            ]\n        }\n    ],\n    \"title\": [\n        {\n            \"text\": \"\\u4e50\\u9ad8\\u4ea7\\u5730\\u6570\\u91cf\\u6392\\u540dtop10\"\n        }\n    ],\n    \"visualMap\": {\n        \"type\": \"continuous\",\n        \"min\": 0,\n        \"max\": 1000,\n        \"inRange\": {\n            \"color\": [\n                \"#50a3ba\",\n                \"#eac763\",\n                \"#d94e5d\"\n            ]\n        },\n        \"calculable\": true,\n        \"splitNumber\": 5,\n        \"orient\": \"vertical\",\n        \"showLabel\": true\n    }\n};\n        chart_9ab8f29d09654d3a9b88385195ff6ff5.setOption(option_9ab8f29d09654d3a9b88385195ff6ff5);\n    });\n</script>\n"},"transient":{}}],"source":"bar2 = Bar() \nbar2.add_xaxis(province_top10.index.tolist())\nbar2.add_yaxis('',province_top10.values.tolist())\nbar2.set_global_opts(\n    title_opts = opts.TitleOpts(title = '乐高产地数量排名top10'),\n    visualmap_opts = opts.VisualMapOpts(max_=1000)\n)\nbar2.render_notebook()"},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"715B82CFCABE4AA3866CC86FC0692EAD","trusted":true,"mdEditEnable":false},"source":"### 国内各省份乐高销量分布图"},{"cell_type":"code","execution_count":11,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"01A7CFF959164652923611F4B1CB7FD4","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"province\n广东    172277\n上海     49649\n浙江     42537\n北京     18003\n江苏      5309\n山东      3177\n天津      2837\n湖北      1130\n福建       838\n湖南       802\nName: purchase_num, dtype: int64"},"transient":{}}],"source":"province_num = df_tb.groupby('province')['purchase_num'].sum().sort_values(ascending=False)\n\nprovince_num[:10]"},{"cell_type":"code","execution_count":12,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"7244996A5A5E441286814C2A383EECE3","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"<pyecharts.render.display.HTML at 0x7f71ef40c748>","text/html":"<script>\n    require.config({\n        paths: {\n            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n        }\n    });\n</script>\n\n    <div id=\"25f27b861fef45cf911e768ddc6e5868\" style=\"width:900px; height:500px;\"></div>\n\n\n<script>\n    require(['echarts', 'china'], function(echarts) {\n        var chart_25f27b861fef45cf911e768ddc6e5868 = echarts.init(\n            document.getElementById('25f27b861fef45cf911e768ddc6e5868'), 'white', {renderer: 'canvas'});\n        var option_25f27b861fef45cf911e768ddc6e5868 = {\n    \"color\": [\n        \"#c23531\",\n        \"#2f4554\",\n        \"#61a0a8\",\n        \"#d48265\",\n        \"#749f83\",\n        \"#ca8622\",\n        \"#bda29a\",\n        \"#6e7074\",\n        \"#546570\",\n        \"#c4ccd3\",\n        \"#f05b72\",\n        \"#ef5b9c\",\n        \"#f47920\",\n        \"#905a3d\",\n        \"#fab27b\",\n        \"#2a5caa\",\n        \"#444693\",\n        \"#726930\",\n        \"#b2d235\",\n        \"#6d8346\",\n        \"#ac6767\",\n        \"#1d953f\",\n        \"#6950a1\",\n        \"#918597\"\n    ],\n    \"series\": [\n        {\n            \"type\": \"map\",\n            \"label\": {\n                \"show\": true,\n                \"position\": \"top\",\n                \"margin\": 8,\n                \"fontSize\": 12\n            },\n            \"mapType\": \"china\",\n            \"data\": [\n                {\n                    \"name\": \"\\u5e7f\\u4e1c\",\n                    \"value\": 172277\n                },\n                {\n                    \"name\": \"\\u4e0a\\u6d77\",\n                    \"value\": 49649\n                },\n                {\n                    \"name\": \"\\u6d59\\u6c5f\",\n                    \"value\": 42537\n                },\n                {\n                    \"name\": \"\\u5317\\u4eac\",\n                    \"value\": 18003\n                },\n                {\n                    \"name\": \"\\u6c5f\\u82cf\",\n                    \"value\": 5309\n                },\n                {\n                    \"name\": \"\\u5c71\\u4e1c\",\n                    \"value\": 3177\n                },\n                {\n                    \"name\": \"\\u5929\\u6d25\",\n                    \"value\": 2837\n                },\n                {\n                    \"name\": \"\\u6e56\\u5317\",\n                    \"value\": 1130\n                },\n                {\n                    \"name\": \"\\u798f\\u5efa\",\n                    \"value\": 838\n                },\n                {\n                    \"name\": \"\\u6e56\\u5357\",\n                    \"value\": 802\n                },\n                {\n                    \"name\": \"\\u8fbd\\u5b81\",\n                    \"value\": 764\n                },\n                {\n                    \"name\": \"\\u7f8e\\u56fd\",\n                    \"value\": 379\n                },\n                {\n                    \"name\": \"\\u6c5f\\u897f\",\n                    \"value\": 236\n                },\n                {\n                    \"name\": \"\\u5e7f\\u897f\",\n                    \"value\": 184\n                },\n                {\n                    \"name\": \"\\u5b89\\u5fbd\",\n                    \"value\": 107\n                },\n                {\n                    \"name\": \"\\u6fb3\\u5927\\u5229\\u4e9a\",\n                    \"value\": 96\n                },\n                {\n                    \"name\": \"\\u6cb3\\u5357\",\n                    \"value\": 61\n                },\n                {\n                    \"name\": \"\\u9ed1\\u9f99\\u6c5f\",\n                    \"value\": 18\n                },\n                {\n                    \"name\": \"\\u9999\\u6e2f\",\n                    \"value\": 13\n                },\n                {\n                    \"name\": \"\\u56db\\u5ddd\",\n                    \"value\": 12\n                },\n                {\n                    \"name\": \"\\u65e5\\u672c\",\n                    \"value\": 8\n                },\n                {\n                    \"name\": \"\\u53f0\\u6e7e\",\n                    \"value\": 2\n                }\n            ],\n            \"roam\": true,\n            \"zoom\": 1,\n            \"showLegendSymbol\": true\n        }\n    ],\n    \"legend\": [\n        {\n            \"data\": [\n                \"\"\n            ],\n            \"selected\": {\n                \"\": true\n            },\n            \"show\": true\n        }\n    ],\n    \"tooltip\": {\n        \"show\": true,\n        \"trigger\": \"item\",\n        \"triggerOn\": \"mousemove|click\",\n        \"axisPointer\": {\n            \"type\": \"line\"\n        },\n        \"textStyle\": {\n            \"fontSize\": 14\n        },\n        \"borderWidth\": 0\n    },\n    \"title\": [\n        {\n            \"text\": \"\\u56fd\\u5185\\u5404\\u4ea7\\u5730\\u4e50\\u9ad8\\u9500\\u91cf\\u5206\\u5e03\\u56fe\"\n        }\n    ],\n    \"visualMap\": {\n        \"type\": \"continuous\",\n        \"min\": 0,\n        \"max\": 172277,\n        \"inRange\": {\n            \"color\": [\n                \"#50a3ba\",\n                \"#eac763\",\n                \"#d94e5d\"\n            ]\n        },\n        \"calculable\": true,\n        \"splitNumber\": 5,\n        \"orient\": \"vertical\",\n        \"showLabel\": true\n    }\n};\n        chart_25f27b861fef45cf911e768ddc6e5868.setOption(option_25f27b861fef45cf911e768ddc6e5868);\n    });\n</script>\n"},"transient":{}}],"source":"map1 = Map()\nmap1.add(\"\",[list(z) for z in zip(province_num.index.tolist(),province_num.values.tolist())],\n       maptype='china')\nmap1.set_global_opts(\n    title_opts = opts.TitleOpts(title='国内各产地乐高销量分布图'),\n    visualmap_opts = opts.VisualMapOpts(max_=172277)\n)\nmap1.render_notebook()"},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"098280091C034B5E8BBDF87275C2CFA1","trusted":true,"mdEditEnable":false},"source":"### 天猫乐高价格分布"},{"cell_type":"code","execution_count":13,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"D64A972DB69B40C8A187069E5111FFE6","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"0~50元        895\n100~200元     701\n50~100元      486\n500~1000元    411\n300~500元     370\n200~300元     288\n1000元以上      260\nName: price, dtype: int64"},"transient":{}}],"source":"cut_bins = [0,50,100,200,300,500,1000,8888]  \ncut_labels = ['0~50元', '50~100元', '100~200元', '200~300元', '300~500元', '500~1000元', '1000元以上']\n\nprice_cut = pd.cut(df_tb['price'],bins=cut_bins,labels=cut_labels)\nprice_num = price_cut.value_counts()\nprice_num"},{"cell_type":"code","execution_count":14,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"79230CCE718C42C48B5D6E640D18DEF8","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"<pyecharts.render.display.HTML at 0x7f71ef420400>","text/html":"<script>\n    require.config({\n        paths: {\n            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n        }\n    });\n</script>\n\n    <div id=\"c0a7e2037dfb4aefba27ed1941985c0f\" style=\"width:900px; height:500px;\"></div>\n\n\n<script>\n    require(['echarts'], function(echarts) {\n        var chart_c0a7e2037dfb4aefba27ed1941985c0f = echarts.init(\n            document.getElementById('c0a7e2037dfb4aefba27ed1941985c0f'), 'white', {renderer: 'canvas'});\n        var option_c0a7e2037dfb4aefba27ed1941985c0f = {\n    \"color\": [\n        \"#c23531\",\n        \"#2f4554\",\n        \"#61a0a8\",\n        \"#d48265\",\n        \"#749f83\",\n        \"#ca8622\",\n        \"#bda29a\",\n        \"#6e7074\",\n        \"#546570\",\n        \"#c4ccd3\",\n        \"#f05b72\",\n        \"#ef5b9c\",\n        \"#f47920\",\n        \"#905a3d\",\n        \"#fab27b\",\n        \"#2a5caa\",\n        \"#444693\",\n        \"#726930\",\n        \"#b2d235\",\n        \"#6d8346\",\n        \"#ac6767\",\n        \"#1d953f\",\n        \"#6950a1\",\n        \"#918597\"\n    ],\n    \"series\": [\n        {\n            \"type\": \"bar\",\n            \"data\": [\n                895,\n                486,\n                701,\n                288,\n                370,\n                411,\n                260\n            ],\n            \"barCategoryGap\": \"20%\",\n            \"label\": {\n                \"show\": true,\n                \"position\": \"top\",\n                \"margin\": 8,\n                \"fontSize\": 12\n            }\n        }\n    ],\n    \"legend\": [\n        {\n            \"data\": [\n                \"\"\n            ],\n            \"selected\": {\n                \"\": true\n            },\n            \"show\": true\n        }\n    ],\n    \"tooltip\": {\n        \"show\": true,\n        \"trigger\": \"item\",\n        \"triggerOn\": \"mousemove|click\",\n        \"axisPointer\": {\n            \"type\": \"line\"\n        },\n        \"textStyle\": {\n            \"fontSize\": 14\n        },\n        \"borderWidth\": 0\n    },\n    \"yAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            }\n        }\n    ],\n    \"xAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            },\n            \"data\": [\n                \"0~50\\u5143\",\n                \"50~100\\u5143\",\n                \"100~200\\u5143\",\n                \"200~300\\u5143\",\n                \"300~500\\u5143\",\n                \"500~1000\\u5143\",\n                \"1000\\u5143\\u4ee5\\u4e0a\"\n            ]\n        }\n    ],\n    \"title\": [\n        {\n            \"text\": \"\\u4e0d\\u540c\\u4ef7\\u683c\\u533a\\u95f4\\u7684\\u5546\\u54c1\\u6570\\u91cf\"\n        }\n    ],\n    \"visualMap\": {\n        \"type\": \"continuous\",\n        \"min\": 0,\n        \"max\": 900,\n        \"inRange\": {\n            \"color\": [\n                \"#50a3ba\",\n                \"#eac763\",\n                \"#d94e5d\"\n            ]\n        },\n        \"calculable\": true,\n        \"splitNumber\": 5,\n        \"orient\": \"vertical\",\n        \"showLabel\": true\n    }\n};\n        chart_c0a7e2037dfb4aefba27ed1941985c0f.setOption(option_c0a7e2037dfb4aefba27ed1941985c0f);\n    });\n</script>\n"},"transient":{}}],"source":"bar3 = Bar() \nbar3.add_xaxis(['0~50元', '50~100元', '100~200元', '200~300元', '300~500元', '500~1000元', '1000元以上'])\nbar3.add_yaxis('', [895, 486, 701, 288, 370, 411, 260]) \nbar3.set_global_opts(title_opts=opts.TitleOpts(title='不同价格区间的商品数量'),\n                     visualmap_opts=opts.VisualMapOpts(max_=900)) \nbar3.render_notebook()"},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"DBE5E3946C264B3EB984622255DECAA3","trusted":true,"mdEditEnable":false},"source":"### 不同价格区间的销售额整体表现"},{"cell_type":"code","execution_count":15,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"A89ED175042D49A9B4A6B94970B63CE4","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"price_cut\n0~50元         3276343.91\n50~100元       4254628.19\n100~200元      9163543.91\n200~300元      4562817.64\n300~500元      8885389.32\n500~1000元     9250876.30\n1000元以上      18742166.89\nName: sales_volume, dtype: float64"},"transient":{}}],"source":"df_tb['price_cut'] = price_cut \n\ncut_purchase = df_tb.groupby('price_cut')['sales_volume'].sum()\ncut_purchase"},{"cell_type":"code","execution_count":16,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"31F43C1BC1644CD78C547EF7D231772E","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"<pyecharts.render.display.HTML at 0x7f71ef420da0>","text/html":"<script>\n    require.config({\n        paths: {\n            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n        }\n    });\n</script>\n\n    <div id=\"1e954836733c40b89311531161a02c6b\" style=\"width:900px; height:500px;\"></div>\n\n\n<script>\n    require(['echarts'], function(echarts) {\n        var chart_1e954836733c40b89311531161a02c6b = echarts.init(\n            document.getElementById('1e954836733c40b89311531161a02c6b'), 'white', {renderer: 'canvas'});\n        var option_1e954836733c40b89311531161a02c6b = {\n    \"color\": [\n        \"#EF9050\",\n        \"#3B7BA9\",\n        \"#6FB27C\",\n        \"#FFAF34\",\n        \"#D8BFD8\",\n        \"#00BFFF\",\n        \"#7FFFAA\"\n    ],\n    \"series\": [\n        {\n            \"type\": \"pie\",\n            \"clockwise\": true,\n            \"data\": [\n                {\n                    \"name\": \"0~50\\u5143\",\n                    \"value\": 3276343.91\n                },\n                {\n                    \"name\": \"50~100\\u5143\",\n                    \"value\": 4254628.1899999995\n                },\n                {\n                    \"name\": \"100~200\\u5143\",\n                    \"value\": 9163543.91\n                },\n                {\n                    \"name\": \"200~300\\u5143\",\n                    \"value\": 4562817.64\n                },\n                {\n                    \"name\": \"300~500\\u5143\",\n                    \"value\": 8885389.320000002\n                },\n                {\n                    \"name\": \"500~1000\\u5143\",\n                    \"value\": 9250876.3\n                },\n                {\n                    \"name\": \"1000\\u5143\\u4ee5\\u4e0a\",\n                    \"value\": 18742166.89\n                }\n            ],\n            \"radius\": [\n                \"35%\",\n                \"60%\"\n            ],\n            \"center\": [\n                \"50%\",\n                \"50%\"\n            ],\n            \"label\": {\n                \"show\": true,\n                \"position\": \"top\",\n                \"margin\": 8,\n                \"fontSize\": 12,\n                \"formatter\": \"{b}:{d}%\"\n            },\n            \"rippleEffect\": {\n                \"show\": true,\n                \"brushType\": \"stroke\",\n                \"scale\": 2.5,\n                \"period\": 4\n            }\n        }\n    ],\n    \"legend\": [\n        {\n            \"data\": [\n                \"0~50\\u5143\",\n                \"50~100\\u5143\",\n                \"100~200\\u5143\",\n                \"200~300\\u5143\",\n                \"300~500\\u5143\",\n                \"500~1000\\u5143\",\n                \"1000\\u5143\\u4ee5\\u4e0a\"\n            ],\n            \"selected\": {},\n            \"show\": true,\n            \"left\": \"2%\",\n            \"top\": \"15%\",\n            \"orient\": \"vertical\"\n        }\n    ],\n    \"tooltip\": {\n        \"show\": true,\n        \"trigger\": \"item\",\n        \"triggerOn\": \"mousemove|click\",\n        \"axisPointer\": {\n            \"type\": \"line\"\n        },\n        \"textStyle\": {\n            \"fontSize\": 14\n        },\n        \"borderWidth\": 0\n    },\n    \"title\": [\n        {\n            \"text\": \"\\u4e0d\\u540c\\u4ef7\\u683c\\u533a\\u95f4\\u7684\\u9500\\u552e\\u989d\\u6574\\u4f53\\u8868\\u73b0\"\n        }\n    ]\n};\n        chart_1e954836733c40b89311531161a02c6b.setOption(option_1e954836733c40b89311531161a02c6b);\n    });\n</script>\n"},"transient":{}}],"source":"data_pair = [list(z) for z in zip(cut_purchase.index.tolist(), cut_purchase.values.tolist())]\n# 绘制饼图\npie1 = Pie() \npie1.add('', data_pair, radius=['35%', '60%'])\npie1.set_global_opts(title_opts=opts.TitleOpts(title='不同价格区间的销售额整体表现'), \n                     legend_opts=opts.LegendOpts(orient='vertical', pos_top='15%', pos_left='2%'))\npie1.set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{d}%\"))\npie1.set_colors(['#EF9050', '#3B7BA9', '#6FB27C', '#FFAF34', '#D8BFD8', '#00BFFF', '#7FFFAA'])\npie1.render_notebook() "},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"CC15147C437A4B51A3D4913E444B7E7A","trusted":true,"mdEditEnable":false},"source":"### 商品标题词云图"},{"cell_type":"code","execution_count":18,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"E3496EE40CFF4F7890958EE3F4B88CAC","trusted":true,"collapsed":false,"scrolled":false},"outputs":[],"source":"def get_cut_words(content_series):\n    # 读入停用词表\n    stop_words = [] \n    \n    # with open(r\"E:\\py练习\\数据分析\\stop_words.txt\", 'r', encoding='utf-8') as f:\n    #     lines = f.readlines()\n    #     for line in lines:\n    #         stop_words.append(line.strip())\n\n    # 添加关键词\n    my_words = ['乐高', '悟空小侠', '大颗粒', '小颗粒'] \n    for i in my_words:\n        jieba.add_word(i) \n\n    # 自定义停用词\n#     my_stop_words = []\n#     stop_words.extend(my_stop_words)               \n\n    # 分词\n    word_num = jieba.lcut(content_series.str.cat(sep='。'), cut_all=False)\n\n    # 条件筛选\n    word_num_selected = [i for i in word_num if i not in stop_words and len(i)>=2]\n    \n    return word_num_selected"},{"cell_type":"code","execution_count":19,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"EA4A3C9A59F143CFA22D3FC01ED8A42A","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"stream","text":"Building prefix dict from the default dictionary ...\nLoading model from cache /tmp/jieba.cache\nLoading model cost 1.916 seconds.\nPrefix dict has been built succesfully.\n","name":"stderr"},{"output_type":"execute_result","metadata":{},"data":{"text/plain":"['乐高', '旗舰店', '官网', '悟空小侠', '系列', '80012', '孙悟', 'LEGO', '乐高', '71043']"},"transient":{}}],"source":"text = get_cut_words(content_series=df_tb['goods_name']) \ntext[:10]"},{"cell_type":"code","execution_count":21,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"E50151E2C96043E48A61919DBC2738B4","trusted":true,"collapsed":false,"scrolled":false},"outputs":[],"source":"# import stylecloud\n# from IPython.display import Image # 用于在jupyter lab中显示本地图片\n\n# # 绘制词云图\n# stylecloud.gen_stylecloud(\n#     text=' '.join(text),\n#     collocations=False,\n#     font_path=r'‪C:\\Windows\\Fonts\\msyh.ttc',\n#     icon_name='fas fa-plane',\n#     size = 768,\n#     output_name='淘宝乐高标题词云图.png'\n# )\n# Image(filename='淘宝乐高标题词云图.png')\n"},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"4263C455BF75402A856D2E7F307CC5EA","trusted":true,"mdEditEnable":false},"source":"# 乐高天猫旗舰店数据分析\n## 数据读入"},{"cell_type":"code","execution_count":22,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"78BC85B4DEC9448090455BE35C51FA25","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"                                   title    age_range    price sales_num  \\\n0                乐高哈利波特系列霍格沃茨城堡71043成人收藏  适用年龄范围：16+岁  3999.00       139   \n1          乐高旗舰店Ideas系列21319中央咖啡厅老友记收藏送礼     适用年龄16岁+   699.00       454   \n2   乐高旗舰店官网2020年新品10269 哈雷戴维森®肥仔®摩托车成人收藏          NaN   999.00       276   \n3  乐高旗舰店官网2020年新品Ideas系列21320恐龙化石男女孩玩具礼物          NaN   599.00       359   \n4        乐高旗舰店官网10874智能蒸汽火车遥控轨道大颗粒益智积木玩具  适用年龄范围：2-5岁   549.00       806   \n\n   comment_num     color_cat  \n0          511  71043 霍格沃兹城堡  \n1         1299             无  \n2          509             无  \n3          524             无  \n4         2884   10874蒸汽智能火车  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>title</th>\n      <th>age_range</th>\n      <th>price</th>\n      <th>sales_num</th>\n      <th>comment_num</th>\n      <th>color_cat</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>乐高哈利波特系列霍格沃茨城堡71043成人收藏</td>\n      <td>适用年龄范围：16+岁</td>\n      <td>3999.00</td>\n      <td>139</td>\n      <td>511</td>\n      <td>71043 霍格沃兹城堡</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>乐高旗舰店Ideas系列21319中央咖啡厅老友记收藏送礼</td>\n      <td>适用年龄16岁+</td>\n      <td>699.00</td>\n      <td>454</td>\n      <td>1299</td>\n      <td>无</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>乐高旗舰店官网2020年新品10269 哈雷戴维森®肥仔®摩托车成人收藏</td>\n      <td>NaN</td>\n      <td>999.00</td>\n      <td>276</td>\n      <td>509</td>\n      <td>无</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>乐高旗舰店官网2020年新品Ideas系列21320恐龙化石男女孩玩具礼物</td>\n      <td>NaN</td>\n      <td>599.00</td>\n      <td>359</td>\n      <td>524</td>\n      <td>无</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>乐高旗舰店官网10874智能蒸汽火车遥控轨道大颗粒益智积木玩具</td>\n      <td>适用年龄范围：2-5岁</td>\n      <td>549.00</td>\n      <td>806</td>\n      <td>2884</td>\n      <td>10874蒸汽智能火车</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"transient":{}}],"source":"df_tm = pd.read_csv(r'/home/kesci/input/legao3225/天猫乐高旗舰店数据.csv')\ndf_tm.head()"},{"cell_type":"code","execution_count":23,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"8F16F8AAB0844F3180ED174879558829","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"stream","text":"<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 392 entries, 0 to 391\nData columns (total 6 columns):\ntitle          392 non-null object\nage_range      334 non-null object\nprice          392 non-null object\nsales_num      392 non-null object\ncomment_num    392 non-null int64\ncolor_cat      392 non-null object\ndtypes: int64(1), object(5)\nmemory usage: 18.5+ KB\n","name":"stdout"}],"source":"df_tm.info()"},{"cell_type":"markdown","metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"A8F6D562519B45CC819E961AD85DFF6C","trusted":true,"mdEditEnable":false},"source":"1. 重复值处理\n2. age_range：暂不处理\n3. price：价格处理/类型转换\n4. sales_num: 类型转换\n5. color_cat：暂不处理"},{"cell_type":"code","execution_count":24,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"3B2F959AE4D545E981164972F3A8B50E","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"                                   title    age_range   price  sales_num  \\\n0                乐高哈利波特系列霍格沃茨城堡71043成人收藏  适用年龄范围：16+岁  3999.0        139   \n1          乐高旗舰店Ideas系列21319中央咖啡厅老友记收藏送礼     适用年龄16岁+   699.0        454   \n2   乐高旗舰店官网2020年新品10269 哈雷戴维森®肥仔®摩托车成人收藏          NaN   999.0        276   \n3  乐高旗舰店官网2020年新品Ideas系列21320恐龙化石男女孩玩具礼物          NaN   599.0        359   \n4        乐高旗舰店官网10874智能蒸汽火车遥控轨道大颗粒益智积木玩具  适用年龄范围：2-5岁   549.0        806   \n\n   comment_num     color_cat  \n0          511  71043 霍格沃兹城堡  \n1         1299             无  \n2          509             无  \n3          524             无  \n4         2884   10874蒸汽智能火车  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>title</th>\n      <th>age_range</th>\n      <th>price</th>\n      <th>sales_num</th>\n      <th>comment_num</th>\n      <th>color_cat</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>乐高哈利波特系列霍格沃茨城堡71043成人收藏</td>\n      <td>适用年龄范围：16+岁</td>\n      <td>3999.0</td>\n      <td>139</td>\n      <td>511</td>\n      <td>71043 霍格沃兹城堡</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>乐高旗舰店Ideas系列21319中央咖啡厅老友记收藏送礼</td>\n      <td>适用年龄16岁+</td>\n      <td>699.0</td>\n      <td>454</td>\n      <td>1299</td>\n      <td>无</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>乐高旗舰店官网2020年新品10269 哈雷戴维森®肥仔®摩托车成人收藏</td>\n      <td>NaN</td>\n      <td>999.0</td>\n      <td>276</td>\n      <td>509</td>\n      <td>无</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>乐高旗舰店官网2020年新品Ideas系列21320恐龙化石男女孩玩具礼物</td>\n      <td>NaN</td>\n      <td>599.0</td>\n      <td>359</td>\n      <td>524</td>\n      <td>无</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>乐高旗舰店官网10874智能蒸汽火车遥控轨道大颗粒益智积木玩具</td>\n      <td>适用年龄范围：2-5岁</td>\n      <td>549.0</td>\n      <td>806</td>\n      <td>2884</td>\n      <td>10874蒸汽智能火车</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"transient":{}}],"source":"df_tm.drop_duplicates(inplace=True)\n\n# 价格处理\ndef transform_price(x):\n    if '-' in x:\n        return (float(x.split('-')[1]) - float(x.split('-')[0]))/2\n    else:\n        return x \n\n# 价格转换\ndf_tm['price'] = df_tm.price.apply(lambda x:transform_price(x)).astype('float')\n\n# 使用平均值填充缺失值\ndf_tm['sales_num'] = df_tm.sales_num.replace('无',200)\n\n#转换类型\ndf_tm['sales_num'] = df_tm.sales_num.astype('int')\ndf_tm.head() "},{"cell_type":"code","execution_count":25,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"BD360E7663B34A978B7851DFC30B3033","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"stream","text":"<class 'pandas.core.frame.DataFrame'>\nInt64Index: 369 entries, 0 to 385\nData columns (total 6 columns):\ntitle          369 non-null object\nage_range      317 non-null object\nprice          369 non-null float64\nsales_num      369 non-null int64\ncomment_num    369 non-null int64\ncolor_cat      369 non-null object\ndtypes: float64(1), int64(2), object(3)\nmemory usage: 20.2+ KB\n","name":"stdout"}],"source":"df_tm.info()"},{"cell_type":"code","execution_count":26,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"246EBA75BE2E472F9354DD33A73578B0","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"                       title    age_range   price  sales_num  comment_num  \\\n0    乐高哈利波特系列霍格沃茨城堡71043成人收藏  适用年龄范围：16+岁  3999.0        139          511   \n1   Ideas系列21319中央咖啡厅老友记收藏送礼     适用年龄16岁+   699.0        454         1299   \n2   新品10269 哈雷戴维森®肥仔®摩托车成人收藏          NaN   999.0        276          509   \n3  新品Ideas系列21320恐龙化石男女孩玩具礼物          NaN   599.0        359          524   \n4   10874智能蒸汽火车遥控轨道大颗粒益智积木玩具  适用年龄范围：2-5岁   549.0        806         2884   \n\n      color_cat  sales_volume  \n0  71043 霍格沃兹城堡      555861.0  \n1             无      317346.0  \n2             无      275724.0  \n3             无      215041.0  \n4   10874蒸汽智能火车      442494.0  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>title</th>\n      <th>age_range</th>\n      <th>price</th>\n      <th>sales_num</th>\n      <th>comment_num</th>\n      <th>color_cat</th>\n      <th>sales_volume</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>乐高哈利波特系列霍格沃茨城堡71043成人收藏</td>\n      <td>适用年龄范围：16+岁</td>\n      <td>3999.0</td>\n      <td>139</td>\n      <td>511</td>\n      <td>71043 霍格沃兹城堡</td>\n      <td>555861.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Ideas系列21319中央咖啡厅老友记收藏送礼</td>\n      <td>适用年龄16岁+</td>\n      <td>699.0</td>\n      <td>454</td>\n      <td>1299</td>\n      <td>无</td>\n      <td>317346.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>新品10269 哈雷戴维森®肥仔®摩托车成人收藏</td>\n      <td>NaN</td>\n      <td>999.0</td>\n      <td>276</td>\n      <td>509</td>\n      <td>无</td>\n      <td>275724.0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>新品Ideas系列21320恐龙化石男女孩玩具礼物</td>\n      <td>NaN</td>\n      <td>599.0</td>\n      <td>359</td>\n      <td>524</td>\n      <td>无</td>\n      <td>215041.0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>10874智能蒸汽火车遥控轨道大颗粒益智积木玩具</td>\n      <td>适用年龄范围：2-5岁</td>\n      <td>549.0</td>\n      <td>806</td>\n      <td>2884</td>\n      <td>10874蒸汽智能火车</td>\n      <td>442494.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"transient":{}}],"source":"df_tm['title'] = df_tm.title.str.replace('乐高旗舰店|官网|2020年', '')\n\n#销售额\ndf_tm['sales_volume'] = df_tm['sales_num'] * df_tm['price']\n\ndf_tm.head()"},{"cell_type":"code","execution_count":27,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"8EE0737B78C846F0876A0391EB01B323","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"title\n悟空小侠系列80012孙悟空齐天大圣黄金机甲              5897\n42096保时捷911RSR赛车成人送礼收藏车模            3818\n乐高5月新品悟空小侠系列80008悟空小侠云霄战机孙悟空齐天大圣    2779\n42093雪佛兰科尔维特ZR1跑车积木玩具汽车             2727\n城市组60226火星探测航天飞机                    2424\n幻影忍者系列 71699 雷霆突击战车                 2265\n城市组太空系列60226火星探测航天飞机积木玩具            1862\n乐高60215消防局男女孩儿童益智玩具积木送礼             1814\n10874智能蒸汽火车遥控轨道大颗粒益智积木玩具            1615\n10874智能蒸汽火车遥控轨道积木玩具                 1565\nName: sales_num, dtype: int64"},"transient":{}}],"source":"rank_top10 = df_tm.groupby('title')['sales_num'].sum().sort_values(ascending=False).head(10)\nrank_top10"},{"cell_type":"code","execution_count":28,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"71F40A82BC274FD58AF7812292B45EE1","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"                                title  sales_num\n105              好朋友41366奥莉薇亚的草莓蛋糕咖啡店       1117\n304         乐高5月新品悟空小侠系列80009猪大厨移动钉耙车       1549\n144               10874智能蒸汽火车遥控轨道积木玩具       1565\n172           42093雪佛兰科尔维特ZR1跑车积木玩具汽车       1755\n128           乐高60215消防局男女孩儿童益智玩具积木送礼       1813\n8            城市组太空系列60226火星探测航天飞机积木玩具       1862\n103                  城市组60226火星探测航天飞机       2424\n296  乐高5月新品悟空小侠系列80008悟空小侠云霄战机孙悟空齐天大圣       2453\n135          42096保时捷911RSR赛车成人送礼收藏车模       2750\n300            悟空小侠系列80012孙悟空齐天大圣黄金机甲       4765","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>title</th>\n      <th>sales_num</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>105</th>\n      <td>好朋友41366奥莉薇亚的草莓蛋糕咖啡店</td>\n      <td>1117</td>\n    </tr>\n    <tr>\n      <th>304</th>\n      <td>乐高5月新品悟空小侠系列80009猪大厨移动钉耙车</td>\n      <td>1549</td>\n    </tr>\n    <tr>\n      <th>144</th>\n      <td>10874智能蒸汽火车遥控轨道积木玩具</td>\n      <td>1565</td>\n    </tr>\n    <tr>\n      <th>172</th>\n      <td>42093雪佛兰科尔维特ZR1跑车积木玩具汽车</td>\n      <td>1755</td>\n    </tr>\n    <tr>\n      <th>128</th>\n      <td>乐高60215消防局男女孩儿童益智玩具积木送礼</td>\n      <td>1813</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>城市组太空系列60226火星探测航天飞机积木玩具</td>\n      <td>1862</td>\n    </tr>\n    <tr>\n      <th>103</th>\n      <td>城市组60226火星探测航天飞机</td>\n      <td>2424</td>\n    </tr>\n    <tr>\n      <th>296</th>\n      <td>乐高5月新品悟空小侠系列80008悟空小侠云霄战机孙悟空齐天大圣</td>\n      <td>2453</td>\n    </tr>\n    <tr>\n      <th>135</th>\n      <td>42096保时捷911RSR赛车成人送礼收藏车模</td>\n      <td>2750</td>\n    </tr>\n    <tr>\n      <th>300</th>\n      <td>悟空小侠系列80012孙悟空齐天大圣黄金机甲</td>\n      <td>4765</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"transient":{}}],"source":"rank_top10 = df_tm.sort_values('sales_num', ascending=False).head(10)[['title', 'sales_num']]\nrank_top10 = rank_top10.sort_values('sales_num')\nrank_top10"},{"cell_type":"code","execution_count":29,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"BC530492648D460E89E93AF4E278FCB2","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"<pyecharts.render.display.HTML at 0x7f71ed0b6048>","text/html":"<script>\n    require.config({\n        paths: {\n            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n        }\n    });\n</script>\n\n    <div id=\"9e55debf02fe41f3b855d736d395087a\" style=\"width:900px; height:500px;\"></div>\n\n\n<script>\n    require(['echarts'], function(echarts) {\n        var chart_9e55debf02fe41f3b855d736d395087a = echarts.init(\n            document.getElementById('9e55debf02fe41f3b855d736d395087a'), 'white', {renderer: 'canvas'});\n        var option_9e55debf02fe41f3b855d736d395087a = {\n    \"color\": [\n        \"#c23531\",\n        \"#2f4554\",\n        \"#61a0a8\",\n        \"#d48265\",\n        \"#749f83\",\n        \"#ca8622\",\n        \"#bda29a\",\n        \"#6e7074\",\n        \"#546570\",\n        \"#c4ccd3\",\n        \"#f05b72\",\n        \"#ef5b9c\",\n        \"#f47920\",\n        \"#905a3d\",\n        \"#fab27b\",\n        \"#2a5caa\",\n        \"#444693\",\n        \"#726930\",\n        \"#b2d235\",\n        \"#6d8346\",\n        \"#ac6767\",\n        \"#1d953f\",\n        \"#6950a1\",\n        \"#918597\"\n    ],\n    \"series\": [\n        {\n            \"type\": \"bar\",\n            \"data\": [\n                1117,\n                1549,\n                1565,\n                1755,\n                1813,\n                1862,\n                2424,\n                2453,\n                2750,\n                4765\n            ],\n            \"barCategoryGap\": \"20%\",\n            \"label\": {\n                \"show\": true,\n                \"position\": \"right\",\n                \"margin\": 8,\n                \"fontSize\": 12\n            },\n            \"rippleEffect\": {\n                \"show\": true,\n                \"brushType\": \"stroke\",\n                \"scale\": 2.5,\n                \"period\": 4\n            }\n        }\n    ],\n    \"legend\": [\n        {\n            \"data\": [\n                \"\"\n            ],\n            \"selected\": {\n                \"\": true\n            },\n            \"show\": true\n        }\n    ],\n    \"tooltip\": {\n        \"show\": true,\n        \"trigger\": \"item\",\n        \"triggerOn\": \"mousemove|click\",\n        \"axisPointer\": {\n            \"type\": \"line\"\n        },\n        \"textStyle\": {\n            \"fontSize\": 14\n        },\n        \"borderWidth\": 0\n    },\n    \"yAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            },\n            \"data\": [\n                \"\\u597d\\u670b\\u53cb41366\\u5965\\u8389\\u8587\\u4e9a\\u7684\\u8349\\u8393\\u86cb\\u7cd5\\u5496\\u5561\\u5e97\",\n                \"\\u4e50\\u9ad85\\u6708\\u65b0\\u54c1\\u609f\\u7a7a\\u5c0f\\u4fa0\\u7cfb\\u521780009\\u732a\\u5927\\u53a8\\u79fb\\u52a8\\u9489\\u8019\\u8f66\",\n                \"10874\\u667a\\u80fd\\u84b8\\u6c7d\\u706b\\u8f66\\u9065\\u63a7\\u8f68\\u9053\\u79ef\\u6728\\u73a9\\u5177\",\n                \"42093\\u96ea\\u4f5b\\u5170\\u79d1\\u5c14\\u7ef4\\u7279ZR1\\u8dd1\\u8f66\\u79ef\\u6728\\u73a9\\u5177\\u6c7d\\u8f66\",\n                \"\\u4e50\\u9ad860215\\u6d88\\u9632\\u5c40\\u7537\\u5973\\u5b69\\u513f\\u7ae5\\u76ca\\u667a\\u73a9\\u5177\\u79ef\\u6728\\u9001\\u793c\",\n                \"\\u57ce\\u5e02\\u7ec4\\u592a\\u7a7a\\u7cfb\\u521760226\\u706b\\u661f\\u63a2\\u6d4b\\u822a\\u5929\\u98de\\u673a\\u79ef\\u6728\\u73a9\\u5177\",\n                \"\\u57ce\\u5e02\\u7ec460226\\u706b\\u661f\\u63a2\\u6d4b\\u822a\\u5929\\u98de\\u673a\",\n                \"\\u4e50\\u9ad85\\u6708\\u65b0\\u54c1\\u609f\\u7a7a\\u5c0f\\u4fa0\\u7cfb\\u521780008\\u609f\\u7a7a\\u5c0f\\u4fa0\\u4e91\\u9704\\u6218\\u673a\\u5b59\\u609f\\u7a7a\\u9f50\\u5929\\u5927\\u5723\",\n                \"42096\\u4fdd\\u65f6\\u6377911RSR\\u8d5b\\u8f66\\u6210\\u4eba\\u9001\\u793c\\u6536\\u85cf\\u8f66\\u6a21\",\n                \"\\u609f\\u7a7a\\u5c0f\\u4fa0\\u7cfb\\u521780012\\u5b59\\u609f\\u7a7a\\u9f50\\u5929\\u5927\\u5723\\u9ec4\\u91d1\\u673a\\u7532\"\n            ]\n        }\n    ],\n    \"xAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            }\n        }\n    ],\n    \"title\": [\n        {\n            \"text\": \"\\u4e50\\u9ad8\\u65d7\\u8230\\u5e97\\u6708\\u9500\\u91cf\\u6392\\u540dTop10\\u5546\\u54c1\"\n        }\n    ]\n};\n        chart_9e55debf02fe41f3b855d736d395087a.setOption(option_9e55debf02fe41f3b855d736d395087a);\n    });\n</script>\n"},"transient":{}}],"source":"x_data = rank_top10.title.values.tolist()\ny_data = rank_top10.sales_num.values.tolist() \n\nbar1 = Bar() \nbar1.add_xaxis(x_data)\nbar1.add_yaxis('',y_data)\nbar1.set_global_opts(title_opts=opts.TitleOpts(title='乐高旗舰店月销量排名Top10商品'),\n                    #visualmap_opts = opts.VisualMapOpts(max_=5000)\n                    )\nbar1.set_series_opts(label_opts=opts.LabelOpts(position='right'))\nbar1.reversal_axis() \nbar1.render_notebook()"},{"cell_type":"code","execution_count":30,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"5F54B93D92D54662B7A29A6D3DD6B6C6","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"100~200元     86\n50~100元      71\n500~1000元    61\n0~50元        52\n200~300元     39\n300~500元     35\n1000元以上      25\nName: price, dtype: int64"},"transient":{}}],"source":"cut_bins = [0,200,400,600,800,1000,2000,9469]\ncut_labels = ['0~50元', '50~100元', '100~200元', '200~300元', '300~500元', '500~1000元', '1000元以上']\n\nprice_cut = pd.cut(df_tm['price'],bins=cut_bins,labels=cut_labels)\nprice_num = price_cut.value_counts()\nprice_num"},{"cell_type":"code","execution_count":31,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"7846F316D8B5493B8F7BC2C39FD60C70","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"<pyecharts.render.display.HTML at 0x7f71ed0b6e10>","text/html":"<script>\n    require.config({\n        paths: {\n            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n        }\n    });\n</script>\n\n    <div id=\"958c6af98d8b4033a29a8921a00aa830\" style=\"width:900px; height:500px;\"></div>\n\n\n<script>\n    require(['echarts'], function(echarts) {\n        var chart_958c6af98d8b4033a29a8921a00aa830 = echarts.init(\n            document.getElementById('958c6af98d8b4033a29a8921a00aa830'), 'white', {renderer: 'canvas'});\n        var option_958c6af98d8b4033a29a8921a00aa830 = {\n    \"color\": [\n        \"#c23531\",\n        \"#2f4554\",\n        \"#61a0a8\",\n        \"#d48265\",\n        \"#749f83\",\n        \"#ca8622\",\n        \"#bda29a\",\n        \"#6e7074\",\n        \"#546570\",\n        \"#c4ccd3\",\n        \"#f05b72\",\n        \"#ef5b9c\",\n        \"#f47920\",\n        \"#905a3d\",\n        \"#fab27b\",\n        \"#2a5caa\",\n        \"#444693\",\n        \"#726930\",\n        \"#b2d235\",\n        \"#6d8346\",\n        \"#ac6767\",\n        \"#1d953f\",\n        \"#6950a1\",\n        \"#918597\"\n    ],\n    \"series\": [\n        {\n            \"type\": \"bar\",\n            \"data\": [\n                52,\n                71,\n                86,\n                39,\n                35,\n                61,\n                25\n            ],\n            \"barCategoryGap\": \"20%\",\n            \"label\": {\n                \"show\": true,\n                \"position\": \"top\",\n                \"margin\": 8,\n                \"fontSize\": 12\n            }\n        }\n    ],\n    \"legend\": [\n        {\n            \"data\": [\n                \"\"\n            ],\n            \"selected\": {\n                \"\": true\n            },\n            \"show\": true\n        }\n    ],\n    \"tooltip\": {\n        \"show\": true,\n        \"trigger\": \"item\",\n        \"triggerOn\": \"mousemove|click\",\n        \"axisPointer\": {\n            \"type\": \"line\"\n        },\n        \"textStyle\": {\n            \"fontSize\": 14\n        },\n        \"borderWidth\": 0\n    },\n    \"yAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            }\n        }\n    ],\n    \"xAxis\": [\n        {\n            \"show\": true,\n            \"scale\": false,\n            \"nameLocation\": \"end\",\n            \"nameGap\": 15,\n            \"gridIndex\": 0,\n            \"inverse\": false,\n            \"offset\": 0,\n            \"splitNumber\": 5,\n            \"minInterval\": 0,\n            \"splitLine\": {\n                \"show\": false,\n                \"lineStyle\": {\n                    \"width\": 1,\n                    \"opacity\": 1,\n                    \"curveness\": 0,\n                    \"type\": \"solid\"\n                }\n            },\n            \"data\": [\n                \"0~50\\u5143\",\n                \"50~100\\u5143\",\n                \"100~200\\u5143\",\n                \"200~300\\u5143\",\n                \"300~500\\u5143\",\n                \"500~1000\\u5143\",\n                \"1000\\u5143\\u4ee5\\u4e0a\"\n            ]\n        }\n    ],\n    \"title\": [\n        {\n            \"text\": \"\\u4e50\\u9ad8\\u65d7\\u8230\\u5e97\\u4e0d\\u540c\\u4ef7\\u683c\\u533a\\u95f4\\u5546\\u54c1\\u6570\\u91cf\"\n        }\n    ],\n    \"visualMap\": {\n        \"type\": \"continuous\",\n        \"min\": 0,\n        \"max\": 90,\n        \"inRange\": {\n            \"color\": [\n                \"#50a3ba\",\n                \"#eac763\",\n                \"#d94e5d\"\n            ]\n        },\n        \"calculable\": true,\n        \"splitNumber\": 5,\n        \"orient\": \"vertical\",\n        \"showLabel\": true\n    }\n};\n        chart_958c6af98d8b4033a29a8921a00aa830.setOption(option_958c6af98d8b4033a29a8921a00aa830);\n    });\n</script>\n"},"transient":{}}],"source":"bar2 = Bar() \nbar2.add_xaxis(['0~50元', '50~100元', '100~200元', '200~300元', '300~500元', '500~1000元', '1000元以上'])\nbar2.add_yaxis('',[52,71,86,39,35,61,25])\nbar2.set_global_opts(title_opts=opts.TitleOpts(title='乐高旗舰店不同价格区间商品数量'),\n                    visualmap_opts = opts.VisualMapOpts(max_=90)\n                    )\nbar2.render_notebook()"},{"cell_type":"code","execution_count":32,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"12F37037782042838EF3730FE745ED5E","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"price_cut\n0~50元         1026784.0\n50~100元       5757306.0\n100~200元     11246532.0\n200~300元      4934247.0\n300~500元      3008934.0\n500~1000元    20173601.0\n1000元以上       7728577.0\nName: sales_volume, dtype: float64"},"transient":{}}],"source":"# 添加列\ndf_tm['price_cut'] = price_cut\ncut_purchase = df_tm.groupby('price_cut')['sales_volume'].sum()\ncut_purchase "},{"cell_type":"code","execution_count":33,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"216297CBE20642A18D3915D4D5AB9F74","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"<pyecharts.render.display.HTML at 0x7f71ef420fd0>","text/html":"<script>\n    require.config({\n        paths: {\n            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n        }\n    });\n</script>\n\n    <div id=\"436cd2159ffd42c090c29b75010cb7b8\" style=\"width:900px; height:500px;\"></div>\n\n\n<script>\n    require(['echarts'], function(echarts) {\n        var chart_436cd2159ffd42c090c29b75010cb7b8 = echarts.init(\n            document.getElementById('436cd2159ffd42c090c29b75010cb7b8'), 'white', {renderer: 'canvas'});\n        var option_436cd2159ffd42c090c29b75010cb7b8 = {\n    \"color\": [\n        \"#EF9050\",\n        \"#3B7BA9\",\n        \"#6FB27C\",\n        \"#FFAF34\",\n        \"#D8BFD8\",\n        \"#00BFFF\",\n        \"#7FFFAA\"\n    ],\n    \"series\": [\n        {\n            \"type\": \"pie\",\n            \"clockwise\": true,\n            \"data\": [\n                {\n                    \"name\": \"0~50\\u5143\",\n                    \"value\": 1026784.0\n                },\n                {\n                    \"name\": \"50~100\\u5143\",\n                    \"value\": 5757306.0\n                },\n                {\n                    \"name\": \"100~200\\u5143\",\n                    \"value\": 11246532.0\n                },\n                {\n                    \"name\": \"200~300\\u5143\",\n                    \"value\": 4934247.0\n                },\n                {\n                    \"name\": \"300~500\\u5143\",\n                    \"value\": 3008934.0\n                },\n                {\n                    \"name\": \"500~1000\\u5143\",\n                    \"value\": 20173601.0\n                },\n                {\n                    \"name\": \"1000\\u5143\\u4ee5\\u4e0a\",\n                    \"value\": 7728577.0\n                }\n            ],\n            \"radius\": [\n                \"35%\",\n                \"60%\"\n            ],\n            \"center\": [\n                \"50%\",\n                \"50%\"\n            ],\n            \"label\": {\n                \"show\": true,\n                \"position\": \"top\",\n                \"margin\": 8,\n                \"fontSize\": 12,\n                \"formatter\": \"{b}:{d}%\"\n            },\n            \"rippleEffect\": {\n                \"show\": true,\n                \"brushType\": \"stroke\",\n                \"scale\": 2.5,\n                \"period\": 4\n            }\n        }\n    ],\n    \"legend\": [\n        {\n            \"data\": [\n                \"0~50\\u5143\",\n                \"50~100\\u5143\",\n                \"100~200\\u5143\",\n                \"200~300\\u5143\",\n                \"300~500\\u5143\",\n                \"500~1000\\u5143\",\n                \"1000\\u5143\\u4ee5\\u4e0a\"\n            ],\n            \"selected\": {},\n            \"show\": true,\n            \"left\": \"2%\",\n            \"top\": \"15%\",\n            \"orient\": \"vertical\"\n        }\n    ],\n    \"tooltip\": {\n        \"show\": true,\n        \"trigger\": \"item\",\n        \"triggerOn\": \"mousemove|click\",\n        \"axisPointer\": {\n            \"type\": \"line\"\n        },\n        \"textStyle\": {\n            \"fontSize\": 14\n        },\n        \"borderWidth\": 0\n    },\n    \"title\": [\n        {\n            \"text\": \"\\u4e0d\\u540c\\u4ef7\\u683c\\u533a\\u95f4\\u7684\\u9500\\u552e\\u989d\\u6574\\u4f53\\u8868\\u73b0\"\n        }\n    ]\n};\n        chart_436cd2159ffd42c090c29b75010cb7b8.setOption(option_436cd2159ffd42c090c29b75010cb7b8);\n    });\n</script>\n"},"transient":{}}],"source":"data_pair =  [list(z) for z in zip(cut_purchase.index.tolist(), cut_purchase.values.tolist())]\n\n# 绘制饼图\npie1 = Pie()\npie1.add('', data_pair, radius=['35%', '60%'])\npie1.set_global_opts(title_opts=opts.TitleOpts(title='不同价格区间的销售额整体表现'), \n                     legend_opts=opts.LegendOpts(orient='vertical', pos_top='15%', pos_left='2%'))\npie1.set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{d}%\"))\npie1.set_colors(['#EF9050', '#3B7BA9', '#6FB27C', '#FFAF34', '#D8BFD8', '#00BFFF', '#7FFFAA'])\npie1.render_notebook() "},{"cell_type":"code","execution_count":34,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"9CA0AC56A03D4E7981D5695B86DBECF6","trusted":true,"collapsed":false,"scrolled":false},"outputs":[{"output_type":"execute_result","metadata":{},"data":{"text/plain":"['乐高', '哈利波', '系列', '霍格', '沃茨', '城堡']"},"transient":{}}],"source":"text = get_cut_words(content_series=df_tm['title'])\ntext[:6]"},{"cell_type":"code","execution_count":36,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"416FD525E0F548BB888FC5D2F179372F","trusted":true,"collapsed":false,"scrolled":false},"outputs":[],"source":"# stylecloud.gen_stylecloud(\n#     text=' '.join(text),\n#     collocations=False,\n#     font_path=r'‪C:\\Windows\\Fonts\\msyh.ttc',\n#     icon_name='fas fa-gamepad',\n#     size=768,\n#     output_name='乐高旗舰店商品标题词云图.png'\n# )\n# Image(filename='乐高旗舰店商品标题词云图.png')"},{"cell_type":"code","execution_count":null,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"9C44EC4094E442748AE9BA42328AAF56","trusted":true,"collapsed":false,"scrolled":false},"outputs":[],"source":""},{"cell_type":"code","execution_count":null,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"5758D5204BD04D4F8749CFC46A944E4C","trusted":true},"outputs":[],"source":""},{"cell_type":"code","execution_count":null,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"E86B5CD2FD9B4265B878E1A2FC0397E8","trusted":true},"outputs":[],"source":""},{"cell_type":"code","execution_count":null,"metadata":{"jupyter":{},"tags":[],"slideshow":{"slide_type":"slide"},"id":"E387DABE4A4B46128A7F8F1D6104DBCC","trusted":true},"outputs":[],"source":""}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python","nbconvert_exporter":"python","file_extension":".py","version":"3.5.2","pygments_lexer":"ipython3"}},"nbformat":4,"nbformat_minor":4}